Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
' VISIO constants and declarations
'
Global Const S_OBJPRP = 1 ' General properties for object
Global Const R_PAGGEN = 10 ' Page general properties
Global Const C_PGDSZ = 6 ' Drawing size type
Global Const C_PGDST = 7 ' Drawing scale type
' Application title
'
Global Const APP_TITLE = "VISIO Stencil Report Wizard"
' String constants
'
Global Const STR_BACKGROUND = "Background" ' name of background page
' Error codes and strings
'
Global Const ERR_WARNING = 0
Global Const ERR_FATAL = 1
Global Const ERR_PROMPT = 2
Global Const ERR_NOVISIO = "Cannot get Visio object."
Global Const ERR_NOSTENCILS = "Please open one or more stencils before running this add-on."
Global Const ERR_NOMASTERS = "No masters on stencil."
Global Const ERR_INPLACE = "STNDOC unable to run with in-place instance of Visio."
Global Const ERR_OPENFILES = "Too many open files. Close one or more open files and run this wizard again."
Global Const ERR_NOTEMPLATE = "An error occurred opening the following template: "
Global Const ERR_NOTEMPLATE2 = "Make sure the file exists and is in the appropriate directory."
Global Const VB_ERROR_STRING_OPENFILES = "Too many open files."
' Limits
'
Global Const MAX_ROWS = 6
Global Const MAX_COLS = 6
Type RECT
left As Double
Top As Double
Bottom As Double
Right As Double
End Type
Type PAGEMETRICS
drawingScale As Double ' drawing scale
pageScale As Double ' page scale
pageHeight As Double ' page height
pageWidth As Double ' page width
Header As Double ' header height
Footer As Double ' footer height
LeftMargin As Double ' page margins
RightMargin As Double
TopMargin As Double
BottomMargin As Double
TextMargin As Double ' text margins
LabelWidth As Double ' label for shape properties
LabelHeight As Double
GridMargin As Double ' grid margins
End Type
Type GRIDMETRICS
masters As Integer ' masters per page
rows As Integer
cols As Integer
RowHeight As Double
ColWidth As Double
End Type
Type DOCMETRICS
Filename As String ' name of stencil
masters As Integer ' total number of masters
PageCount As Integer ' total number of pages
' Options
'
Header As Integer ' show header
Footer As Integer ' show footer
gridlines As Integer ' show gridlines
properties As Integer ' show properties
resize As Integer ' resize masters to fit grid
End Type
Global gDoc As DOCMETRICS
Global gPage As PAGEMETRICS
Global gGrid As GRIDMETRICS
Global gGridArray(0 To MAX_ROWS, 0 To MAX_COLS) As RECT
Global gDocDraw As Visio.Document ' drawing document
Global gWinDraw As Visio.Window ' drawing window
Global gPageBack As Visio.Page ' background page
'Form position
Global g_iFormTop As Integer
Global g_iFormLeft As Integer
' Make sure there is a running instance of Visio
'
Sub appConnect()
Dim stat
If vaoGetObject() <> visOK Then
stat = appMessage(ERR_FATAL, ERR_NOVISIO)
End If
End Sub
' Application initialization
'
Sub appInit()
' Initialize document metrics
docInit
End Sub
Function appMessage(code, message)
Dim status
Dim style
' Pick icon
'
If code = ERR_PROMPT Then
style = 36 ' Question mark & Yes/No
Else
style = 48 ' Exclamation mark & OK
End If
Beep
status = MsgBox(message, style, APP_TITLE)
If code = ERR_FATAL Then
End ' Terminate program
End If
appMessage = status
End Function
Sub CheckIfInPlace()
If g_appVisio.version < 3 Then
Exit Sub
Else
If g_appVisio.Documents.Count Then
If g_appVisio.Documents(1).inplace Then
MsgBox ERR_INPLACE, 48
End
End If
End If
End If
End Sub
Sub docInit()
gDoc.Header = True
gDoc.Footer = True
gDoc.gridlines = True
gDoc.properties = True
gDoc.resize = True
End Sub
Sub formInit(f As Form)
' Set caption
'
f.Caption = APP_TITLE
' Set the form to always be on top
'
SetWindowPos f.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
End Sub
' Compute grid metrics.
'
Sub gridCompute(ByVal rows, ByVal cols)
Dim row
Dim col
Dim tmp
' This routine depends on page metrics.
'
pageCompute gPageBack
gGrid.masters = rows * cols
' Switch rows and cols if necessary for best fit on page.
'
If (pageIsPortrait(gPageBack) And rows < cols) Or (pageIsLandscape(gPageBack) And cols < rows) Then